import Cookies from 'js-cookie'

/**
 * 使用cookie作为缓存
 * @param {} key
 * @returns
 */
const BASEKEY = "KSD_NUXT_"
export const useCache = (key) => {
    const ckey = BASEKEY + key
    return {
        // 设置cookie
        setCache(value, day = 7) {
            Cookies.set(ckey, value, {expires: day, path: '/'});
        },
        // 获取cookie
        getCache() {
            return Cookies.get(ckey);
        },
        // 删除cookie
        remove() {
            Cookies.remove(ckey, {path: '/'});
        }
    }
}

